<?
$wechat_list=select_lines_all_items($table_Prefix."wechat_official","","status != '停用' ","");

//取出指定日期的 公众号数 条数据。
$wechat_member_log=select_lines_all_items($table_Prefix."wechat_member_log","nid desc","",count($wechat_list));

$wechat_member_log_1day=select_lines_all_items($table_Prefix."wechat_member_log","nid desc","date like '%".date("Y-m-d",strtotime("-1 day"))."%'","");
$wechat_member_log_2day=select_lines_all_items($table_Prefix."wechat_member_log","nid desc","date like '%".date("Y-m-d",strtotime("-2 day"))."%'","");
$wechat_member_log_3day=select_lines_all_items($table_Prefix."wechat_member_log","nid desc","date like '%".date("Y-m-d",strtotime("-3 day"))."%'","");

$wechat_member_log_7day=select_lines_all_items($table_Prefix."wechat_member_log","nid desc","date like '%".date("Y-m-d",strtotime("-7 day"))."%'","");

$wechat_member_log_14day=select_lines_all_items($table_Prefix."wechat_member_log","nid desc","date like '%".date("Y-m-d",strtotime("-14 day"))."%'","");

?>


<div class="statistics-box layui-form">




    <div class="layui-form">
        <table class="layui-table">
            <colgroup>
                <col width="60">
                <col>
                <col>
                <col>
                <col>
            </colgroup>
            <thead>
            <tr>
                <th>编号</th>
                <th>公众号</th>
                <th>周增幅</th>
                <th>今天</th>
                <th>昨天</th>
                <th>前天</th>
                <th>大前天</th> 
                <th>上周</th>
                <th>前周</th>
                <th><?echo date("m")?>月</th>
                <th><?echo date("m",strtotime("-1 month"))?>月</th>
                <th><?echo date("m",strtotime("-2 month"))?>月</th>
                <th><?echo date("m",strtotime("-3 month"))?>月</th>
                <th><?echo date("m",strtotime("-4 month"))?>月</th>
                <th><?echo date("m",strtotime("-5 month"))?>月</th>
            </tr>
            </thead>
            <tbody>

            <? for($i=0;$i<count($wechat_list);$i++){?>
                <tr>
                    <td><?echo $i+1?></td>
                    <td><?echo $wechat_list[$i]['name']?></td>

<?

if(substr($wechat_member_log[0]['date'],0,10)==date("Y-m-d"))
{
  $wechat_number_list=transform_2darray_in_1darray_with_new_key($wechat_member_log,"public_id","number");
  $wechat_number_list_1day=transform_2darray_in_1darray_with_new_key($wechat_member_log_1day,"public_id","number");
  $wechat_number_list_2day=transform_2darray_in_1darray_with_new_key($wechat_member_log_2day,"public_id","number");

  $wechat_number_list_3day=transform_2darray_in_1darray_with_new_key($wechat_member_log_3day,"public_id","number");
  //上一周的数据
  $wechat_number_list_7day=transform_2darray_in_1darray_with_new_key($wechat_member_log_7day,"public_id","number");
  $wechat_number_list_14day=transform_2darray_in_1darray_with_new_key($wechat_member_log_14day,"public_id","number");
}
else
{

    $get_total_url = "http://wx.enpingshi.com/get_member_total.php?appid=".$wechat_list[$i]['appid']."&appsecret=".$wechat_list[$i]['appsecret'];

    $pare['ai_master_id']=$wechat_list[$i]['nid'];
    $pare['ai_public_id']=$wechat_list[$i]['public_id'];
    $pare['ai_number']=file_get_contents($get_total_url);;
    $insert_number_2_log=insert_date($table_Prefix."wechat_member_log",$pare);
    $query = mysql_query($insert_number_2_log) or die ("error:".mysql_error());

    //因为新插入了，所以要重新读取一下最新数据
    $wechat_member_log_newest=select_lines_all_items($table_Prefix."wechat_member_log","nid desc","",count($wechat_list));
    $wechat_number_list=transform_2darray_in_1darray_with_new_key($wechat_member_log_newest,"public_id","number");
}

?>

                    <td><?echo $wechat_number_list[$wechat_list[$i]['public_id']]-$wechat_number_list_7day[$wechat_list[$i]['public_id']]?></td>
                    <td><?echo $wechat_number_list[$wechat_list[$i]['public_id']]?>
                        (<?echo $wechat_number_list[$wechat_list[$i]['public_id']]-$wechat_number_list_1day[$wechat_list[$i]['public_id']]?>)
                    </td>
                    <td><?echo $wechat_number_list_1day[$wechat_list[$i]['public_id']]?></td>
                    <td><?echo $wechat_number_list_2day[$wechat_list[$i]['public_id']]?></td>
                    <td><?echo $wechat_number_list_3day[$wechat_list[$i]['public_id']]?></td>

 
                    <td><?echo $wechat_number_list_7day[$wechat_list[$i]['public_id']]?></td>
                    <td><?echo $wechat_number_list_14day[$wechat_list[$i]['public_id']]?></td>

                    <td> / </td>
                    <td> / </td>

                    <td> / </td>
                    <td> / </td>
                    <td> / </td>
                    <td> / </td>

                </tr>
            <?}?>




            </tbody>
        </table>
    </div>



</div>

